<template>
	<el-dialog :visible.sync="visible" :modal-append-to-body="false" :title="keyLan['name']" class="demo-ruleForm">
		<el-form ref="formModel" :model="value" :rules="rules" :label-width="labelWidth" :inline="inline"
			v-bind="$props" v-on="$listeners">
			<!-- <h4 class="orange">基础信息</h4> -->
			<el-row>
				<!-- <slot name="HeaderUrlBefore"></slot>
				<slot name="HeaderUrl">
					<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
						<el-form-item prop="HeaderUrl" :label="keyLan['HeaderUrl'] + ':'">
							<uploadimg v-model="model.HeaderUrl" :max="1"></uploadimg>
						</el-form-item>
					</el-col>
				</slot>
				<slot name="HeaderUrlAfter"></slot> -->
				<slot name="NameBefore"></slot>
				<slot name="Name">
					<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
						<el-form-item prop="Name" :label="keyLan['Name'] + ':'">
							<el-input v-model="model.Name" @keyup.native.enter="save" ref="Name"></el-input>
						</el-form-item>
					</el-col>
				</slot>
				<slot name="NameAfter"></slot>
				<slot name="PhoneBefore"></slot>
				<slot name="Phone">
					<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
						<el-form-item prop="Phone" :label="keyLan['Phone'] + ':'">
							<el-input v-model="model.Phone" @keyup.native.enter="save"></el-input>
						</el-form-item>
					</el-col>
				</slot>
				<slot name="PhoneAfter"></slot>

				<!-- <slot name="EnumStatusBefore"></slot>
				<slot name="EnumStatus">
					<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
						<el-form-item prop="EnumStatus" :label="keyLan['EnumStatus'] + ':'">
							<el-radio-group v-model="model.EnumStatus" @keyup.native.enter="save">
								<el-radio v-for="item in EnumStatus" :key="item.Value" :value="item.Value"
									:label="item.Value">
									{{ enumLanTxt(item.Label) }}
								</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
				</slot>
				<slot name="EnumStatusAfter"></slot> -->
				<slot name="RemarkBefore"></slot>
				<slot name="Remark">
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
						<el-form-item prop="Remark" :label="keyLan['Remark'] + ':'">
							<el-input type="textarea" :rows="2" v-model="model.Remark" style="width: 100%;"
								@keyup.native.enter="save"></el-input>
						</el-form-item>
					</el-col>
				</slot>
				<slot name="RemarkAfter"></slot>
			</el-row>
		</el-form>

		<div slot="footer" class="dialog-footer">
			<el-button type="warning" v-if="isAdd" @click="resetThisVal('model')">{{ comLan["btnReset"] }}</el-button>
			<el-button @click="close">{{ comLan["btnCancel"] }}</el-button>
			<el-button type="success" @click="save" :loading="loading">{{ comLan["btnSave"] }}</el-button>
		</div>
	</el-dialog>
</template>

<script>
import common from "@/common/common.js";
import js from "./js.js";

export default {
	name: "ReferrerAdd",
	components: {},
	props: {
		value: {
			type: Object,
			default: function () {
				return {};
			}
		}
	},
	mixins: [common.baseVM, js],
	data() {
		return {
			model: {
				ReferrerID: 0,
				HeaderUrl: null,
				Name: null,
				Phone: null,
				EnumStatus: 1,
				Pwd: null,
				Remark: null,
			}
		}
	},
	methods: {
		init() { },

		focus() {
			this.$nextTick(() => {
				this.$refs.Name.focus();
			});
		},

		show(scope) {
			this.loadBeforeValSuccess = false;
			this.resetVal("model");
			this.isAdd = scope == null || scope.row == null;
			if (this.isAdd) { //新建
				this.loadBeforeVal();
				this.visible = true;
				this.focus();
				return;
			}
			var id = scope.row.ReferrerID;
			this.get("api/Referrer/Get?id=" + id).then(data => {
				this.model = data.Result;
				this.visible = true;
				this.focus();
			});
		},
		close() {
			this.visible = false;
		},
		save() {
			this.formValidate('formModel', () => {
				var post = JSON.parse(JSON.stringify(this.model));
				this.loading = true;
				this.post('api/Referrer/Save', post).then(data => {
					this.showToast(data.Message, "success");
					this.loading = false;

					this.clearBeforeVal();
					this.close();

					this.$emit("success");

					if (this.isAdd && !!this.$listeners["input"]) {
						this.$emit("input", data.Result);
					}
				}).catch((error) => {
					this.loading = false;
				});
			});
		}
	}
}
</script>
